<template>
  <!-- 工资条 -->
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-row style="padding-top: 25px; padding-left: 20px">
            <el-button type="primary" @click="AddPayrollItems"
              >新建工资条</el-button
            >
            <div style="display: inline; position: relative; left: 844px">
              <el-input
                style="width: 200px"
                placeholder="请输入关键字"
                prefix-icon="el-icon-search"
                v-model="form.schemeName"
                @keyup.enter.native="search"
              >
              </el-input>
            </div>
          </el-row>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div
          class="grid-content bg-purple-dark-two"
          style="padding-top: 20px; padding-left: 20px"
        >
          <el-table :data="tableData" border="true" style="width: 79%">
            <el-table-column
              prop="schemeName"
              label="工资条名称"
              width="190"
              align="center"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="salaryCycle"
              label="关联薪资方案"
              width="190"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="state"
              label="状态"
              width="150"
            >
              <template slot-scope="scope">
                {{
                  scope.row.state == 1
                    ? "未核算"
                    : scope.row.state == 2
                    ? "核算中"
                    : scope.row.state == 3
                    ? "已核算"
                    : "已停用"
                }}
              </template>
            </el-table-column>
            <el-table-column align="center" prop="createTime" label="创建时间">
            </el-table-column>
            <el-table-column
              align="center"
              fixed="right"
              label="操作"
              width="150"
            >
              <template slot-scope="scope">
                <el-button
                  @click.native.prevent="handleEdit(scope.$index, scope.row)"
                  type="text"
                >
                  停用 </el-button
                ><el-button
                  @click.native.prevent="handleEdit(scope.$index, scope.row)"
                  type="text"
                >
                  修改
                </el-button>
                <el-button
                  @click.native.prevent="handleEdit(scope.$index, scope.row)"
                  type="text"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页器 -->
          <div class="block" style="margin-top: 15px; margin-left: -400px">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="form.currentPage"
              :page-sizes="[2, 5, 10, 20]"
              :page-size="form.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-row>
        <el-col :span="24"
          ><div class="grid-content">
            <span style="font-size: larger;">&nbsp;&nbsp;&nbsp;&nbsp;基本信息</span>
            </div
        ></el-col>
      </el-row>
      <el-form ref="form" :model="formData" label-width="80px">
        <el-form-item label="项目名称">
          <el-input v-model="formData.projectName"></el-input>
        </el-form-item>
        <el-form-item label="项目类型">
          <el-select v-model="formData.projectType" placeholder="请选择">
            <el-option label="税前加项" value="1"></el-option>
            <el-option label="税前减项" value="2"></el-option>
            <el-option label="税费项" value="3"></el-option>
            <el-option label="税后加项" value="4"></el-option>
            <el-option label="税后减项" value="5"></el-option>
            <el-option label="统计项" value="6"></el-option>
            <el-option label="其他项" value="7"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="舍入规则">
          <el-select v-model="formData.roundingRules" placeholder="请选择">
            <el-option label="原始数据" value="1"></el-option>
            <el-option label="四舍五入" value="2"></el-option>
            <el-option label="向上舍入数字" value="3"></el-option>
            <el-option label="向下舍入数字" value="4"></el-option>
          </el-select>
          <span v-show="formData.roundingRules == 2">
            保留
            <el-input v-model="formData.retain" style="width: 60px"></el-input
            >位小数
          </span>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="formData.remark"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">{{ sub }}</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
  
  <script>
export default {
  data() {
    return {
      tableData: [],
      form: {
        currentPage: 1,
        pageSize: 5,
        schemeName: "",
      },
      formData: {
        id: undefined,
        projectName: "",
        projectType: "",
        roundingRules: "",
        retain: "",
        remark: "",
      },
      dialogVisible: false,
      title: "添加项目",
      total: 0,
    };
  },
  created() {},
  methods: {
    AddPayrollItems() {
      this.dialogVisible = true;
      this.sub = "创建项目";
      this.title = "添加项目";
    },
    // 修改
    updateSalary(id) {
      this.$router.push({ path: "/AddSalaryCalculate", query: { id, id } });
    },
    // 停用
    stopSalary(id) {
      this.$confirm("是否停用此方案, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http("salary/stopSalary", {
          params: {
            id: id,
          },
        }).then((res) => {
          if (res.data.code === 200) {
            this.$message(res.data.data);
            this.getSalaryList();
          } else {
            this.$message.error(res.data.data);
          }
        });
      });
    },
    // 取消
    cancel() {
      this.dialogVisible = false;
      this.formData = {
        id: undefined,
        projectName: "",
        projectType: "",
        roundingRules: "",
        retain: "",
        remark: "",
      };
    },
    // 获取薪资方案列表
    search() {
      this.getSalaryList();
    },
    getSalaryList() {
      this.$http.post("salary/getSalaryList", this.form).then((res) => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total;
        } else {
          this.$message.error(res.data.data);
        }
      });
    },
    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      this.form.currentPage = 1;
      this.form.pageSize = val;
      this.getSalaryList();
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      this.form.currentPage = val;
      this.getSalaryList();
    },
  },
};
</script>
  
  <style scoped>
.block {
  padding-left: 800px;
}
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: white;
  height: 90px;
}
.bg-purple-dark-two {
  background: white;
  height: 600px;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>